package com.nowcoder.code.hjnc;

public class NC160 {

    public int search(int[] nums, int target) {

        int start = 0, end = nums.length - 1;
        int mid;

        while (start <= end) {
            mid = (start + end) >> 1;
            if (nums[mid] == target) {
                return mid;
            } else if (nums[mid] > target) {
                end = mid - 1;
            } else {
                start = mid + 1;
            }
        }

        return -1;

    }

}
